package com.smartcampusbackend;

import com.smartcampusbackend.service.AcademicWarningService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.CommandLineRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SpringBootApplication
public class SmartCampusBackendApplication {
    
    private static final Logger logger = LoggerFactory.getLogger(SmartCampusBackendApplication.class);

	public static void main(String[] args) {
		ConfigurableApplicationContext context = SpringApplication.run(SmartCampusBackendApplication.class, args);
	}
	
	@Bean
	public CommandLineRunner initAcademicWarnings(AcademicWarningService academicWarningService) {
	    return args -> {
	        logger.info("应用启动完成，开始检查并生成学业预警...");
	        try {
	            academicWarningService.generateWarningsFromGrades();
	            logger.info("学业预警生成完成");
	        } catch (Exception e) {
	            logger.error("启动时生成学业预警失败: " + e.getMessage(), e);
	        }
	    };
	}
}
